#include<bits/stdc++.h>

using namespace std;

int main(){
	int n = 19;
	int t = 0, res = 0 ,cnt = 0;
    while(n != 1 && res < 1e5){
        t = n;
        res = 0;
        while(t){
            res += (t % 10) * (t % 10);
            t /= 10;
        }
        n = res;
        cout << res << endl;
           
    }
    
	return 0;
} 
